package com.igeekhome.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeekhome.biz.ICustomerInfoService;
import com.igeekhome.biz.ICustomerServiceService;
import com.igeekhome.biz.ISessionMessageService;
import com.igeekhome.biz.ISystemMessageService;
import com.igeekhome.pojo.CustomerInfo;
import com.igeekhome.pojo.CustomerService;
import com.igeekhome.pojo.SessionMessage;
import com.igeekhome.pojo.SystemMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {
    @Autowired
    private ISessionMessageService iSessionMessageService;
    @Autowired
    private ISystemMessageService iSystemMessageService;
    @Autowired
    private ICustomerServiceService iCustomerServiceService;
    @Autowired
    private ICustomerInfoService iCustomerInfoService;
    @RequestMapping( "/index")
    public String ToPageIndex(HttpSession session,Model model)
    {
//       if(session.getAttribute("check")==null)
//        {
//            return "index";
//        }
//        else

        QueryWrapper<SessionMessage> QueryWrapper=new QueryWrapper();
        QueryWrapper<SystemMessage> systemMessageQueryWrapper=new QueryWrapper();
//        QueryWrapper.eq("customerServiceId",(int)session.getAttribute("csid"));
        iSessionMessageService.count(QueryWrapper);
        //客服收到的消息数
        if( iSessionMessageService.count(QueryWrapper)!=0)
        {
            session.setAttribute("session",iSessionMessageService.count(QueryWrapper));
        }
        else
        {
            session.setAttribute("session",0);
        }
        //系统公告
        session.setAttribute("content",iSystemMessageService.getById("1").getContent());
        session.setAttribute("title",iSystemMessageService.getById("1").getTitle());
        session.setAttribute("createtime",iSystemMessageService.getById("1").getCreatetime());
        //数据显示
        QueryWrapper<CustomerService> queryWrapper1 = new QueryWrapper();
        QueryWrapper<CustomerInfo> queryWrapper2 = new QueryWrapper();
        queryWrapper1.eq("state","在线");
        queryWrapper2.eq("state","在线");
        session.setAttribute("CustomerNum",iCustomerInfoService.count());
        session.setAttribute("OnlineCustomerNum",iCustomerInfoService.count(queryWrapper2));
        session.setAttribute("CustomerServiceNum",iCustomerServiceService.count());
        session.setAttribute("OnlineCustomerServiceNum",iCustomerServiceService.count(queryWrapper1));


        queryWrapper2.clear();
        queryWrapper2.eq("channel","客服录入");
        session.setAttribute("i",iCustomerInfoService.count(queryWrapper2));

        System.out.println(iCustomerInfoService.count(queryWrapper2));


        queryWrapper2.clear();
        queryWrapper2.eq("channel","网页介入");
        session.setAttribute("j",iCustomerInfoService.count(queryWrapper2));

        System.out.println(iCustomerInfoService.count(queryWrapper2));
        //统计在线
        QueryWrapper<CustomerService> customerServiceQueryWrapper=new QueryWrapper<>();
        customerServiceQueryWrapper.eq("state","在线");
        session.setAttribute("statecs",this.iCustomerServiceService.list(customerServiceQueryWrapper));
        session.setAttribute("statecount",this.iCustomerServiceService.list(customerServiceQueryWrapper).size());
        return "/index";
    }
    @RequestMapping("/Customer-index")
        public String Customer_index(HttpSession session)
    {
        //统计客户在线人数
        QueryWrapper<CustomerInfo> customerInfoQueryWrapper=new QueryWrapper<>();
        customerInfoQueryWrapper.eq("state","在线");
        session.setAttribute("customerstate",this.iCustomerInfoService.list(customerInfoQueryWrapper));
        session.setAttribute("customerstatecount",this.iCustomerInfoService.list(customerInfoQueryWrapper).size());
        return "Customer-index";
    }
    @RequestMapping("/")
    public  String login()
    {
        return "login";
    }
    @RequestMapping("/login")
    public  String Tologin()
    {
        return "login";
    }
    @RequestMapping("/register")
    public String Toregister()
    {
        return "register";
    }
//    @RequestMapping("/CustomerService")
//    public String ToCustomerService()
//    {
//
//        return "CustomerService";
//    }
    @RequestMapping("/Customer")
    public  String ToCustomer()
    {
        return "Customer";
    }
    @RequestMapping("/Session")
    public  String ToSession()
    {
        return "Session";
    }
    @RequestMapping("/Blacklist")
    public  String ToBlacklist()
    {
        return "Blacklist";
    }
    @RequestMapping("CustomerSelf")
    public String cs()
    {
        return "CustomerSelf";
    }
    @RequestMapping("/Customer-login")
    public  String toCustomer_login()
    {
        return "Customer-login";
    }
    @RequestMapping("/Customer-register")
    public String toCustomer_register()
    {
        return "Customer-register";
    }
    @RequestMapping("/CustomerPersonal")
    public String toCustomerPersonal()
    {
        return "CustomerPersonal";
    }
    @RequestMapping("/CustomerServiceChoose")
    public  String toCustomerServiceChoose()
    {
        return "CustomerServiceChoose";
    }
    @RequestMapping("/Service")
    public String toService()
    {
        return "Service";
    }
    @RequestMapping("/chat")
    public String chat(HttpSession session) {

        return "chat2";
    }


}
